<template>
	<view class="full-page" v-if="totalPage">
		
	</view>
	<view class="content" v-else>
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="交易记录" titleStyle="{'color': '#000'}">
			
		</u-navbar>
		<view class="huibg">
			<view class="top">
				<!-- 修改弹窗 -->
				<!-- <picker class="santxt" @change="bindPickerChange" :value="month - 1" :range="array">
					{{month}}<text>月</text>
					<image :src="'/images/duo.png' | formatImgUrl" class="sanpic" mode=""></image>
				</picker>
				<picker style="margin-left: 20px;" class="santxt" @change="bindPickerChange1" :value="index"
					:range="array1">
					<text>{{array1[index]}}</text>
					<image :src="'/images/duo.png' | formatImgUrl" class="sanpic" mode=""></image>
				</picker> -->

				<view class="santxt" @tap="showMonth=true">
					{{year}}<text>年</text>
				</view>
				<view class="santxt" @tap="showMonth=true">
					{{month}}<text>月</text>
					<image :src="'/images/duo.png' | formatImgUrl" class="sanpic" mode=""></image>
				</view>
				<view style="margin-left: 20px;" class="santxt" @tap="showType=true">
					<text>{{array1[index]}}</text>
					<image :src="'/images/duo.png' | formatImgUrl" class="sanpic" mode=""></image>
				</view>
			</view>
			<view class="rubox">
				<view class="ruli" v-if="index!=3">
					<view class="title">
						已入账金额
					</view>
					<view class="rutxt">
						{{row.booked_money?row.booked_money.toFixed(2):'0.00'}}元
					</view>
				</view>
				<view class="ruli" v-if="index!=3">
					<view class="title">
						进行中订单
					</view>
					<view class="rutxt">
						{{row.ing_money?row.ing_money.toFixed(2):'0.00'}}元
					</view>
				</view>
				<view class="ruli" v-if="index==3">
					<view class="title">
						提现金额
					</view>
					<view class="rutxt">
						{{row.finance_money?row.finance_money.toFixed(2):'0.00'}}元
					</view>
				</view>
			</view>
		</view>

		<view class="main">
			<view class="empytView" v-if="!list.total">
				<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
				<!-- <view>- 空列表 -</view> -->
			</view>
			<view class="liebox" v-for="item in logList" @click="tz(item.type,item.id)">
				<image :src="item.pic | formatImgUrl" class="head" mode="" v-if="item.type == 5"></image>
				<image :src="'/images/baobao.png' | formatImgUrl" class="head" mode=""
					v-if="item.type == 7 ||item.type == 6 || item.type == 1 || item.type == 2 || item.type == 3 || item.type == 4">
				</image>
				<view class="liecen">
					<view class="name" v-if="item.type == 1">
						充值
					</view>

					<view class="name" v-if="item.type == 2">
						消费
					</view>
					<view class="yitxt" v-if="item.type == 2">
						{{item.use_type == 1?'微信':'粮币'}}消费
					</view>

					<view class="name" v-if="item.type == 3">
						兑换
					</view>

					<view class="name" v-if="item.type == 4">
						提现
					</view>
					<view class="yitxt" v-if="item.type == 4">
						提现{{item.pay_type == 1?'银行卡':item.pay_type == 2?'微信':'支付宝'}}
					</view>


					<view class="name" v-if="item.type == 5">
						{{item.username}}
					</view>
					<view class="yitxt" v-if="item.type == 5">
						订单收益
					</view>
					<view class="yitxt" v-if="item.type == 6">
						vip充值
					</view>
					<view class="yitxt" v-if="item.type ==7">
						取消订单
					</view>
					<view class="yitxt" v-if="item.type ==8">
						订单部分退款
					</view>
					<view class="yitxt" v-if="item.type ==9">
						订单全部退款
					</view>
					<view class="yitxt" v-if="item.type == 1 ">
						粮币充值
					</view>
					<view class="yitxt" v-if=" item.type == 3">
						佣金兑换
					</view>
					<view class="yitxt">
						{{$options.filters.parseTime(item.create_time,'{y} / {m} / {d} {h}:{i}:{s}') }}
					</view>
				</view>
				<view class="lieyou">
					<view class="lietitle" v-if="item.type == 1 || item.type == 3">
						+{{item.price}}
					</view>

					<view class="lietitle active" v-if="item.type == 2 || item.type == 4 || item.type == 6">
						-{{item.price}}
					</view>

					<view class="lietitle" :style="item.jie_type==0?'color:#999':''"
						v-if="item.type == 5||item.type == 7||item.type == 8||item.type == 9">
						+{{item.price}}
					</view>

					<view class="zantxt" v-if="item.type == 4">
						<block v-if="item.status == 3">已取消</block>
						<block v-else>{{item.status?(item.status == 1?'已打款':'拒绝'):'审批中'}}</block>
					</view>
					<view class="zantxt" v-if="item.type == 5">
						{{item.jie_type?'已结算入账':'未结算暂未入账'}}
					</view>
				</view>
			</view>
		</view>

		<u-popup :show="showMonth" mode="bottom" @close="showMonth=false">
			<view class="custom-bot">
				<view class="title">
					月份选择
				</view>
				<picker-view :value="months" @change="changeMonth"  class="picker-view">
					<picker-view-column>
						<view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="(item,index) in array" :key="index">{{item}}月</view>
					</picker-view-column>
				</picker-view>

				<view class="marginBorder"></view>
				<view class="btn" @tap="showMonth=false,onSearch()">
					确认选择
				</view>
			</view>

		</u-popup>

		<u-popup :show="showType" mode="bottom" @close="closeType">
			<view class="custom-bot">
				<view class="title">
					账单选择
				</view>
				<picker-view :value="types" @change="changeType" class="picker-view">
					<picker-view-column>
						<view class="item" v-for="(item,index) in array1" :key="index">{{item}}</view>
					</picker-view-column>
				</picker-view>

				<view class="marginBorder"></view>
				<view class="btn" @tap="showType=false,onSearch()">
					确认选择
				</view>
			</view>

		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				// 选择月
				array: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
				array1: ['全部账单', '收入账单', '支出账单', "提现账单"],
				index: 0,
				month: new Date().getMonth() + 1,
				year: new Date().getFullYear(),
				row: {},
				list: {},
				page: 1,
				logList: [],
				type: 0,
				months: [1, 0],
				years: [],
				showType: false,
				showMonth: false,
				types: [0],
				totalPage: true
			}
		},
		onLoad(ops) {
			if (ops.type && ops.type == 1) {
				// this.type = type
				this.index = 3
			}
			// this.getList()
			let years = []
			for (let i = 2023; i <= 2123; i++) {
				years.push(i)
			}
			this.years = years
			this.months[0] = 0
			this.months[1] = new Date().getMonth()
		},
		onShow() {
			this.page = 1;
			this.list = [];
			this.logList = [];
			this.getList()
		},
		// 上拉加载
		onReachBottom() {
			if (this.list.current_page < this.list.last_page) {
				this.page++; // 页数加一，加载下一页数据
				this.getList();
			}
		},
		methods: {
			closeType(){
				this.showType=false
				this.onSearch()
			},
			onSearch() {
				this.page = 1;
				this.list = [];
				this.logList = [];
				this.getList()
			},
			changeMonth(e) {
				this.months = e.detail.value
				
				this.year = this.years[this.months[0]]
				this.month = this.array[this.months[1]]
			},
			changeType(e){
				this.types = e.detail.value
				this.index = e.detail.value[0]
			},
			tz(type, id) {
				if(type == 4){
				uni.navigateTo({
					url: '/pages/finance/finance_dea?id=' + id
				})
				}else{
					uni.navigateTo({
						url: '/showcase/showcase/invoiceDetail?id=' + id + '&bill=1'
					})
				}
			},
			getList() {
				this.$api.default.request('user/billList', {
					page: this.page,
					month: this.month,
					year: this.year,
					index: this.index
				}).then((res) => {
					if (res.code) {
						this.row = res.data
						this.list = res.data.list
						if (res.data.list.current_page > 1) {
							res.data.list.data.forEach((item) => {
								this.logList.push(item)
							})
						} else {
							this.logList = res.data.list.data
						}
					}
					
					this.totalPage = false
				})
			},
			bindPickerChange: function(e) {
				this.month = this.array[e.detail.value]
				this.getList()
			},
			bindPickerChange1: function(e) {

				this.index = e.detail.value
				this.getList()
			},
		}
	}
</script>

<style lang="scss">
	.custom-bot {
		text-align: center;
		background-color: #fff;
		
		.title{
			padding: 20px 0;
			font-family: '思源黑体';
			font-size: 14px;
			font-weight: bold;
			color: #3D3D3D;
		}

		.picker-view {
			width: 750rpx;
			height: 200rpx;
		}

		.item {
			height: 34px;
			line-height: 34px;
			font-family: '思源黑体';
			font-size: 15px;
			font-weight: bold;
			color: #3D3D3D;
		}
		
		.marginBorder{
			width: 100%;
			height: 10px;
			background: #F2F5F2;
		}
		
		.btn{
			margin: 10px auto;
			width: 315px;
			height: 40px;
			line-height: 40px;
			border-radius: 8px;
			background: #45C4B0;
			font-family: '思源黑体';
			font-size: 16px;
			font-weight: bold;
			color: #FFFFFF;
		}
	}

	.content {
		.huibg {
			padding: 40rpx 60rpx 20rpx;
			background: rgba(242, 245, 242, 1);

			.top {
				display: flex;
				align-items: center;
				padding-bottom: 4rpx;

				.santxt {
					font-size: 60rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					padding-right: 4rpx;

					text {
						font-size: 24rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}

				.sanpic {
					position: relative;
					top: -12rpx;
					width: 12rpx;
					height: 8.5rpx;
				}
			}

			.rubox {
				display: flex;
				align-items: center;

				.ruli {
					width: 50%;

					.title {
						font-size: 20rpx;
						font-weight: 300;
						color: #3D3D3D;
					}

					.rutxt {
						font-size: 28rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}
			}
		}

		.main {
			padding: 0 30rpx;

			.liebox {
				display: flex;
				align-items: flex-start;
				justify-content: space-between;
				padding: 20rpx 0;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);

				.head {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					flex-shrink: 0;
				}

				.liecen {
					padding: 0rpx 8rpx 0;
					flex-grow: 1;

					.name {
						font-size: 28rpx;
						font-weight: 500;
						letter-spacing: 0em;
						color: #3D3D3D;
						padding-bottom: 4rpx;
					}

					.yitxt {
						font-size: 20rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #999999;
						padding: 2rpx 0;
					}
				}

				.lieyou {
					flex-shrink: 0;
					text-align: right;
					padding-top: 8rpx;

					.lietitle {
						font-size: 36rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #45C4B0;
						padding-bottom: 4rpx;
					}

					.active {
						color: #3D3D3D;
					}

					.zantxt {
						font-size: 20rpx;
						color: #999999;
					}
				}
			}
		}
	}
</style>